<template>
  <a-form ref="noticeFormRef" :model="noticeModel" :rules="noticeFormRule" v-bind="layout">
    <a-form-item name="title" :label="t('org.notice.title')">
      <a-input v-model:value="noticeModel.title" :placeholder="t('org.notice.formPlhTitle')" />
    </a-form-item>
    <a-form-item name="type" :label="t('org.notice.type')">
      <qc-dictionary-select
        :placeholder="t('org.notice.formPlhType')"
        codeItemId="ORG_NOTICE_TYPE"
        v-model:value="noticeModel.type"
      ></qc-dictionary-select>
    </a-form-item>
    <a-form-item name="content" :label="t('org.notice.content')">
      <a-textarea v-model:value="noticeModel.content" :placeholder="t('org.notice.formPlhContent')" :rows="4" />
    </a-form-item>
    <a-form-item name="status" :label="t('org.notice.status')">
      <a-radio-group v-model:value="noticeModel.status">
        <a-radio :value="true">{{ t('org.notice.statusTrue') }}</a-radio>
        <a-radio :value="false">{{ t('org.notice.statusFalse') }}</a-radio>
      </a-radio-group>
    </a-form-item>
  </a-form>
</template>
<script lang='ts'>
import { defineComponent, ref } from 'vue'
import noticeApi from '/@/api/org/notice'
import { noticeFormRule } from '../interface'
import { useModelForm } from '/@/kit/model-kit'
import { useI18n } from 'vue-i18n'
export default defineComponent({
  props: {
    noticeId: String,
  },
  setup(props, { emit }) {
    const { t } = useI18n()
    const noticeFormRef = ref()
    const noticeModel = ref({})

    const { save } = useModelForm(noticeFormRef, noticeModel, props.noticeId, noticeApi)
    //提交方法
    const onSubmit = () => save().then((res) => emit('submitSuccess', res.data.data))
    const layout = {
      labelCol: { span: 7 },
      wrapperCol: { span: 15 },
    }
    return {
      t,
      noticeFormRef,
      noticeModel,
      noticeFormRule,
      layout,
      onSubmit,
    }
  },
})
</script>